package so.sao.code.service.infrastructure.dozer.convert;

import java.util.Date;

import org.dozer.CustomConverter;

import so.sao.code.dto.request.TagBatchCreate;
import so.sao.code.service.domain.entity.TagBatch;
import so.sao.code.service.infrastructure.enums.PrintFileStatus;
import so.sao.code.service.infrastructure.enums.TAG_BATCH_TYPE;
import so.sao.code.service.infrastructure.enums.TagBatchType;

/**
 * Created by Administrator on 2017/8/17.
 */
public class TagBatchTypeConvert implements CustomConverter {
	@Override
	public Object convert(Object destination, Object sourcee, Class<?> destinationClass, Class<?> sourceClass) {
		TagBatchCreate tagBatchCreate = (TagBatchCreate) sourcee;
		TagBatch tagBatch = new TagBatch();

		tagBatch.setName(tagBatchCreate.getName());
		tagBatch.setEseId(tagBatchCreate.getEseId());
		tagBatch.setTagCount(tagBatchCreate.getTagCount());// 这个数量可以前端算好传过来，重复计算
		tagBatch.setUnitCount(tagBatchCreate.getUnitCount());
		tagBatch.setDuplicate(tagBatchCreate.getDuplicate());
		tagBatch.setType(TAG_BATCH_TYPE.fromValue(tagBatchCreate.getType()));
		// tagBatch.setZipPassword(RandomUtil.getRandomUUID()); // 设置默认的压缩密码
		tagBatch.setUnitTagCount(tagBatchCreate.getTagCount());
		tagBatch.setRedundancy(tagBatchCreate.getRedundancy());
		tagBatch.setRatio(tagBatchCreate.getRatio());

		tagBatch.setPrintFileStatus(PrintFileStatus.TODO.getValue());
		tagBatch.setCreateDate(new Date());// 设置创建时间
		tagBatch.setCodeLength(tagBatchCreate.getCodeLength());
		tagBatch.setDomain(tagBatchCreate.getDomain());
		tagBatch.setTagCount(tagBatch.become().computeTotalTagCount());
		tagBatch.setDuplicate(
				TagBatchType.DUPLICATE.getValue().equals(tagBatchCreate.getType()) ? tagBatchCreate.getDuplicate() : 1);
		// tagBatch.setUnitCount(TagBatchType.NORMAL.getValue().equals(tagBatchCreate.getType())
		// ? 1 : tagBatchCreate.getUnitCount());
		return tagBatch;
	}
}
